def main():
    list1_name = []
    list1_age = []
    list1_sex = []
    list2_name = []
    list2_profess = []
    list2_address = []
    input_file1 = open('student1.txt', 'rb')
    input_file2 = open('student2.txt', 'rb')
    input_file1.readline()
    input_file2.readline()
    file1 = input_file1.readlines()
    file2 = input_file2.readlines()

    for line in file1:
        elements = line.split()
        list1_name.append(elements[0].decode('utf-8'))
        list1_age.append(elements[1].decode('utf-8'))
        list1_sex.append(elements[2].decode('utf-8'))

    for line in file2:
        elements = line.split()
        list2_name.append(elements[0].decode('utf-8'))
        list2_profess.append(elements[1].decode('utf-8'))
        list2_address.append(elements[2].decode('utf-8'))

    count_line = []
    count_line.append("姓名 \t 年龄 \t 性别\t 专业\t 地址\t")
    count_line.append("\n")

    for i in range(len(list1_name)):
        str = ''
        t = "\t"
        if list1_name[i] in list2_name:
            j = list2_name.index(list1_name[i])
            seq = (list1_name[i], list1_age[i], list1_sex[i], list2_profess[j], list2_address[j]) # 字符串序列
            str = t.join(seq)
            str += '\n'
        else:
            seq = (list1_name[i], list1_age[i], list1_sex[i],  '无',  '无') # 字符串序列
            str = t.join(seq)
            str += '\n'
        count_line.append(str)

    for i in range(len(list2_name)):
        str = ''
        t = "\t"
        if list2_name[i] not in list1_name:
            seq = (list2_name[i], "无", "无",  list2_profess[i],  list2_address[i]) # 字符串序列
            str = t.join(seq)
            str += '\n'
            count_line.append(str)

    file3 = open("student3.txt", 'w')
    file3.writelines(count_line)

    input_file1.close()
    input_file2.close()
    file3.close()


if __name__ == '__main__':
    main()
